import { http } from '@/utils/http'
import { IProductResult } from '@/service/index/index'

export interface IBrand {
  brandCode: string
  brandLogo: string
  brandName: string
  createBy: string
  createTime: string
  id: number
  isDeleted: string
  tenantId: string
  updateBy: string
  updateTime: string
}

export interface ICategory {
  id: string
  p_id: string
  type_desc: string
  level: number
}

export interface ISortRule {
  sortField: string
  sortLabel: string
}

export interface IQueryConditionResult {
  brands: IBrand[]
  categories: ICategory[]
  sortRules: ISortRule[]
  statusList: string[]
  tags: string[]
}

export const getQueryCondition = () => {
  return http.get<IQueryConditionResult>('/jeecg-boot/htmmp/main/getQueryCondition')
}

export interface IProductQueryParams {
  brandName: string
  categoryId: string
  sortRule: string
  status: string[]
  tags: string[]
  upcCode: string
  pageNo: number
  pageSize: number
}

export interface IProductQueryResult {
  records: IProductResult[]
  total: number
  size: number
  current: number
  orders: any[]
  optimizeCountSql: boolean
  searchCount: boolean
  maxLimit: any
  countId: any
  pages: number
}

export const productQuery = (query: IProductQueryParams) => {
  return http.get<IProductQueryResult>('/jeecg-boot/htmmp/main/productquery', {
    loading: false,
    ...query,
  })
}
